package com.demo.core.controller;

import com.demo.base.page.IPagableDTO;
import com.demo.base.page.PagableDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.demo.base.model.PartTimeJob;
import com.demo.base.page.IPagableDTO;
import com.demo.base.page.PagableDTO;
import com.demo.base.util.CommonUtil;
import com.demo.core.service.PartTimejobService;

/**
 * 兼职信息
 * Created by jiandandia on 2017/4/4.
 */
@RequestMapping("/PartTime")
@Controller
public class PartTimeJobController {
    @Autowired
    private PartTimejobService partTimejobService;

    /**
     * 添加或更改兼职信息
     */
    @ResponseBody
    @RequestMapping("/addOrupdatePartTimeJob")
    public String newOrupdatePartTimeJob(@RequestBody PartTimeJob partTimeJob){
        try {
            partTimejobService.newOrupdatePartTimeJob(partTimeJob);
        }catch (Exception e){
            return CommonUtil.FAIL;
        }
        return CommonUtil.SUCCESS;
    }

    /**
     * 根据id查询兼职信息
     */
    @ResponseBody
    @RequestMapping("/getPartTimeJobById")
    public PartTimeJob getPartTimeJobById(@RequestBody PartTimeJob partTimeJob){
        try {
            return partTimejobService.getPartTimeJobById(partTimeJob.getId());
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }

    }

    //根据多个条件获取兼职信息
    @ResponseBody
    @RequestMapping("/getPartTimeJobByQuery")
    public IPagableDTO<PartTimeJob> getPartTimeJobByQuery(@RequestBody PartTimeJob partTimeJob, int startRow, int pageSize){

            IPagableDTO pagableDTO = new PagableDTO();
            pagableDTO.setStartRow(startRow);
            pagableDTO.setPageSize(pageSize);
          return  partTimejobService.getPartTimeJobByQuery(partTimeJob, pagableDTO);
    }

    //删除单条或多条兼职信息
    @ResponseBody
    @RequestMapping("/deltePartTimeJobById")
    public String deltePartTimeJobById(@RequestBody String ids){
        try{
            partTimejobService.deltePartTimeJobById(ids);
        }catch(Exception e){
            return CommonUtil.FAIL;
        }
        return CommonUtil.SUCCESS;
    }

    /**
     * //浏览数，每次新增1
     * @param noticeId
     * @return
     */
    @ResponseBody
    @RequestMapping("/addBrowNumber")
    public String addBrowsingNumber(@RequestBody String noticeId){

        try {
            partTimejobService.addBrowsingNumber(noticeId);
        } catch (Exception e) {
            return CommonUtil.FAIL;
        }
        return CommonUtil.SUCCESS;
    }

    /**
     * //关注数，每次新增1
     * @param noticeId
     * @return
     */
    @ResponseBody
    @RequestMapping("/addFollowNumber")
    public String addFollowersNumber(@RequestBody String noticeId){

        try {
            partTimejobService.addFollowersNumber(noticeId);
        } catch (Exception e) {
            return CommonUtil.FAIL;
        }
        return CommonUtil.SUCCESS;
    }

    /**
     * //男生报名数，每次新增1
     * @param id
     * @return
     */
    @ResponseBody
    @RequestMapping("/addManNumber")
    public String addManEnterNumber(@RequestBody String id){

        try {
            partTimejobService.addManEnterNumber(id);
        } catch (Exception e) {
            return CommonUtil.FAIL;
        }
        return CommonUtil.SUCCESS;
    }

    /**
     * //女生报名数，每次新增1
     * @param id
     * @return
     */
    @ResponseBody
    @RequestMapping("/addWoManNumber")
    public String addWoManEnterNumber(@RequestBody String id){

        try {
            partTimejobService.addWoManEnterNumber(id);
        } catch (Exception e) {
            return CommonUtil.FAIL;
        }
        return CommonUtil.SUCCESS;
    }
}
